package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.service.BusinesssellerBaseInfoService;
import com.sl.au.service.BusinesssellerAuthenticationService;
import com.sl.au.service.OptionService;
import com.sl.au.entity.Account;
import com.sl.au.entity.BusinesssellerAuthentication;
@RestController
@RequestMapping(value = "/ui/BusinesssellerAuthentication") 
public class BusinesssellerAuthenticationController extends BaseController{
	
	@Autowired
	BusinesssellerBaseInfoService businesssellerBaseInfoService;
	
	@Autowired
	OptionService optionService; 
	
	@Autowired
	BusinesssellerAuthenticationService businesssellerAuthenticationService;
	/*@Autowired
	UserService userService;
	@Autowired
	RoleService roleService;*/
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index() {
		
		ModelAndView modelAndView = this.createLayoutView("businessseller/businesssellerBaseInfoCheck");

		return modelAndView;
	}
	@RequestMapping(value = "getauthenticationpage", method = RequestMethod.GET)
	public Map<String, Object> getauthenticationpage(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		String key=request.getParameter("key");
		List<BusinesssellerAuthentication> businesssellerAuthentication = businesssellerAuthenticationService.getPage(start, length, key, "createTime", Sort.Direction.DESC);
		int count = businesssellerAuthenticationService.getCount(key);
		map.put("data", businesssellerAuthentication);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
	
	@RequestMapping(value = "accessCheck", method = RequestMethod.POST)
	public Map<String, Object> accessCheck(@RequestBody Map<String, Object> request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String id =(String)request.get("id");
		String memo=(String) request.get("memo");
		int code =businesssellerAuthenticationService.accessCheck(id, this.getMyAccount().getUser(),memo);
		map.put("code", code);
		return map;
	}
	
	@RequestMapping(value = "rejectCheck", method = RequestMethod.POST)
	public Map<String, Object> rejectCheck(@RequestBody Map<String, Object> request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String id =(String)request.get("id");
		String memo=(String) request.get("memo");
		int code =businesssellerAuthenticationService.rejectCheck(id, this.getMyAccount().getUser(),memo);
		map.put("code", code);
		return map;
	}
}

